builder: Allow specifying objects inline
authorMatthias Clasen <mclasen@redhat.com>
Wed, 6 Feb 2019 23:53:06 +0000 (18:53 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 8 Feb 2019 05:09:44 +0000 (00:09 -0500)
In addition to <property name="foo">bar</property> referring
to an object with ID bar, we now also parse
<property name="foo"><object>...
to specify a property 'inline'.

gtk/gtkbuilder.c
gtk/gtkbuilderparser.c
gtk/gtkbuilderprivate.h

index 52244862acfa5ac18b89c31e231f3d8fc291d35d..cbbed790b90e6123bbb46f1f38276b76833bb3f1 100644 (file)
@@ -536,7 +536,7 @@ gtk_builder_get_parameters (GtkBuilder         *builder,
           (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != G_TYPE_FILE))
         {
           GObject *object = g_hash_table_lookup (priv->objects,
-                                                 prop->text->str);
+                                                 g_strstrip (prop->text->str));
 
           if (object)
             {
@@ -722,7 +722,9 @@ _gtk_builder_construct (GtkBuilder  *builder,
    * be set once.
    */
   if (info->constructor ||
-      (info->parent && ((ChildInfo*)info->parent)->internal_child != NULL))
+      (info->parent &&
+       info->parent->tag_type == TAG_CHILD &&
+       ((ChildInfo*)info->parent)->internal_child != NULL))
     param_filter_flags = G_PARAM_CONSTRUCT_ONLY;
   else
     param_filter_flags = G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY;
@@ -758,7 +760,9 @@ _gtk_builder_construct (GtkBuilder  *builder,
       if (construct_parameters->len)
         g_warning ("Can't pass in construct-only parameters to %s", info->id);
     }
-  else if (info->parent && ((ChildInfo*)info->parent)->internal_child != NULL)
+  else if (info->parent &&
+           info->parent->tag_type == TAG_CHILD &&
+           ((ChildInfo*)info->parent)->internal_child != NULL)
     {
       gchar *childname = ((ChildInfo*)info->parent)->internal_child;
       obj = gtk_builder_get_internal_child (builder, info, childname, error);
index 94c5b8b6c1d01332aeab17e8828905e38259691f..2c08df0f023e8ffbdbd34830b896338c5619b118 100644 (file)
 static void free_property_info (PropertyInfo *info);
 static void free_object_info (ObjectInfo *info);
 
-enum {
-  TAG_PROPERTY,
-  TAG_MENU,
-  TAG_REQUIRES,
-  TAG_OBJECT,
-  TAG_CHILD,
-  TAG_SIGNAL,
-  TAG_INTERFACE,
-  TAG_TEMPLATE,
-};
 
 static inline void
 state_push (ParserData *data, gpointer info)
@@ -1066,6 +1056,12 @@ end_element (GMarkupParseContext  *context,
     {
       ObjectInfo *object_info = state_pop_info (data, ObjectInfo);
       ChildInfo* child_info = state_peek_info (data, ChildInfo);
+      PropertyInfo* prop_info = state_peek_info (data, PropertyInfo);
+
+      if (child_info && child_info->tag_type != TAG_CHILD)
+        child_info = NULL;
+      if (prop_info && prop_info->tag_type != TAG_PROPERTY)
+        prop_info = NULL;
 
       if (data->requested_objects && data->inside_requested_object &&
           (data->cur_object_level == data->requested_object_level))
@@ -1089,6 +1085,8 @@ end_element (GMarkupParseContext  *context,
         }
       if (child_info)
         child_info->object = object_info->object;
+      if (prop_info)
+        g_string_assign (prop_info->text, object_info->id);
 
       if (GTK_IS_BUILDABLE (object_info->object) &&
           GTK_BUILDABLE_GET_IFACE (object_info->object)->parser_finished)
index 22577df32d7e86dfed5f6125ffd10ec05caf9c7c..5b71bdf76dbb37266153ead1c5e0a7c6f9afc870 100644 (file)
 
 #include "gtkbuilder.h"
 
+enum {
+  TAG_PROPERTY,
+  TAG_MENU,
+  TAG_REQUIRES,
+  TAG_OBJECT,
+  TAG_CHILD,
+  TAG_SIGNAL,
+  TAG_INTERFACE,
+  TAG_TEMPLATE,
+};
+
 typedef struct {
   guint tag_type;
 } CommonInfo;